#!/usr/bin/node

const log  = console.log,
      argv = process.argv[2];

if(typeof(argv)==='undefined'||
    argv === '--help' ||
    argv === '-h'
){
  help();
}else{
  calc();
}
 
//打印程序的使用说明
function help(){
  const msg = ''
    +'usage:cmd-name [OPTION][expression] \n'
    +'evaluate the expression.\n'
    +'\n'
    +'Mandatory arguments to long options are mandatory for short options too.\n'
    +'-h,--help output help information and exit\n';
  log(msg);
}

//对命令行参数的表达式进行求值
function calc(){
  try{
    log(`${argv}=${eval(argv)}`);
  }catch(e){
    console.error(`${argv}不是合法的数学表达式`);
  }
}
